package com.bg.service.impl;

import com.bg.data.User;
import com.bg.repo.UserRepo;
import com.bg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepo userRepo;

    @Override
    public List<User> getList() {
        return userRepo.findAll();
    }

    @Override
    public User updateUser(User user) {
       return userRepo.save(user);
    }

    @Override
    public void insertUser(List<User> users) {
        //insert和save的区别 insert:主键重复会报错；save：主键重复会更新
        List<User> use = userRepo.insert(users);
        use.forEach(x -> System.out.println(x.getId() + "\t" + x.getName() + "\t" + x.getAddress()));
    }

    @Override
    public void removeUser(int id) {

    }
}
